﻿import cgi
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from entities import *
from entities import Entities
from Entities import *

def Add(SoLuong):
    quimo = QuiMo(SoLuong = SoLuong)
    quimo.put()
    
def Get(keyNguoiDung,QuiMoID=0):
    try:
        nguoidung = NguoiDung.get(db.Key(keyNguoiDung)) 
    except:
        return "Invalid Key"
    quimo_list = []
    if QuiMoID > 0:
        try:
            quimos = QuiMo.get_by_id(QuiMoID)
        except:
            return "Invalid QuiMoID"
        quimo_dict ={}
        quimo_dict['QuiMoID'] = QuiMoID
        quimo_dict['SoLuong'] = quimos.SoLuong
        quimo_list.append(quimo_dict)
    else:
        quimos = QuiMo.all()
        for quimo in quimos:
            quimo_dict ={}
            quimo_dict['QuiMoID'] = quimo.key().id()
            quimo_dict['SoLuong'] = quimo.SoLuong
            quimo_list.append(quimo_dict)
    tuple_quimo = tuple(quimo_list)  
    return tuple_quimo
    